<template>
  <div class="list-container">
    <div class="search-wrap clearfix">
      <div class="search-wrap-conditions fl">
        <el-input v-model="listQuery.condition.keyword" placeholder="搜索关键词" @keyup.native="init()" />
      </div>
      <div class="search-wrap-btn fr">
        <el-button :disabled="loading" @click="resetSearch">重置</el-button>
        <el-button :disabled="loading" type="primary" @click="init">搜索</el-button>
      </div>
    </div>
    <div class="main-wrapper">
      <custom-table :data="listData" :columns="columns">
        <template slot-scope="{row}">
          <el-button type="text" @click="getDetail(row.id)">查看详情</el-button>
        </template>
      </custom-table>
      <pagination :total="total" />
    </div>
  </div>
</template>

<script>
import CustomTable from '@/components/CustomTable/index';
import Pagination from '@/components/Pagination/index';
import { getUsersList } from '@/api/users';

export default {
  name: 'List',
  components: {
    CustomTable,
    Pagination
  },
  data () {
    return {
      loading: false,
      listQuery: {
        condition: {
          keyword: null
        },
        pager: {
          page: 1,
          pageSize: 10
        }
      },
      listData: [],
      total: 0,
      columns: [
        { label: 'ID', value: 'id' },
        { label: '手机', value: 'phoneNum' },
        { label: '用户名', value: 'userName' },
        { label: '资质', value: 'aptitude' },
        { label: '平台认证', value: 'identification' },
        { label: '账号状态', value: 'status' },
        { label: '所在学校', value: 'school' },
        { label: '操作', value: 'todo', width: '180px' }
      ]
    };
  },
  created () {
    this.init();
  },
  methods: {
    init () {
      this.loading = true;
      return;
      getUsersList(this.listQuery).then(res => {
        this.listData = res.records;
        this.total = res.total;
        this.loading = res.loading;
      }).catch(error => {
        this.loading = false;
      });
    },
    resetSearch () {
      this.listQuery = {
        condition: {
          keyword: null
        },
        pager: {
          page: 1,
          pageSize: 10
        }
      };
      this.init();
    },
    pagination ({ page, limit }) {
      this.listQuery.pager.page = page;
      this.listQuery.pager.pageSize = limit;
      this.init();
    },
    getDetail (id) {
      console.log(id);
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
